package com.cqqs.page;

import com.cqqs.common.utils.Convert;
import com.cqqs.utils.ServletUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 表格分页数据对象
 *
 * @author mjxie
 */
@Data
public class TableDataInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;


    @ApiModelProperty("总记录数")
    private long total;


    @ApiModelProperty("列表数据")
    private List<T> records;


    @ApiModelProperty("总页数")
    private Integer pages;

    @ApiModelProperty("当前页数")
    private Integer current;


    /**
     * 表格数据对象
     */
    public TableDataInfo() {
    }

    public TableDataInfo getDataTable(List<T> list) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setRecords(list);
        PageInfo pageInfo = new PageInfo(list);
        int pages = pageInfo.getPages();
        rspData.setTotal(pageInfo.getTotal());
        rspData.setPages(pages);
        rspData.setCurrent(Convert.toInt(ServletUtils.getParameter(TableSupport.PAGE_NUM), 1));
        return rspData;
    }


}
